{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#}
{%- extends 'form_table_layout.html.twig' -%}

{%- block form_widget_compound -%}
    {%- if form.vars.freeze_display_text -%}
        <table {{ block('widget_container_attributes') }}>
            {%- if form.parent is empty and errors|length > 0 -%}
            <tr>
                <td colspan="2">
                    {{- form_errors(form) -}}
                </td>
            </tr>
            {%- endif -%}
            {{- block('form_rows') -}}
            {{- form_rest(form) -}}
        </table>
    {%- else -%}
        {{- form_errors(form) -}}
        {{- block('form_rows') -}}
        {{- form_rest(form) -}}
    {%- endif -%}
{%- endblock form_widget_compound -%}

{%- block form_row -%}
    {%- if form.vars.freeze_display_text -%}
        <tr>
            <th>
                {{- form_label(form) -}}
                {% if form.vars.required %}<span class="attention">※</span>{% endif %}
            </th>
            <td>
                {{- form_errors(form) -}}
                {{- form_widget(form) -}}
            </td>
        </tr>
    {%- else -%}
        {{- form_errors(form) -}}
        {{- form_widget(form) -}}
    {%- endif -%}
{%- endblock form_row -%}

{%- block form_errors -%}
    {%- if errors|length > 0 -%}
        {%- for error in errors -%}
            {%- if freeze_display_text -%}
                <span class="attention">※ {{ error.messageTemplate|trans(error.messageParameters, 'validators')|replace({'{{ field }}': label}) }}<br /></span>
            {%- endif %}
        {%- endfor -%}
    {%- endif -%}
{%- endblock form_errors -%}

{# Widgets #}

{%- block form_widget -%}
    {{- parent() -}}
    {%- if freeze == false -%}
        {%- if help is defined and help is not empty -%}
            <p class="mini"><span class="attention">{{ help|trans({}, translation_domain) }}</span></p>
        {%- endif -%}
    {%- endif -%}
{%- endblock form_widget -%}

{%- block form_widget_simple -%}
    {%- if freeze -%}
        {%- set type = 'hidden' -%}
        {%- if freeze_display_text -%}
            {{- value|default('')|nl2br -}}
        {%- endif -%}
    {%- endif -%}
    {{- parent() -}}
{%- endblock form_widget_simple -%}

{%- block widget_attributes -%}
    {%- if errors|length > 0 -%}
        {%- set style = 'background-color:#ffe8e8;' -%}
        {%- if attr -%}
            {%- if attr['style'] is defined and attr['style']|length > 0 -%}
                {%- set style = style~' '~attr['style'] -%}
            {%- endif -%}
            {%- set attr = attr|merge({'style': style}) -%}
        {%- else -%}
            {%- set attr = {'style': style} -%}
        {%- endif -%}
    {%- endif -%}
    id="{{ id }}" name="{{ full_name }}"{%- if read_only -%} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif -%}
    {%- if freeze == false -%}
        {%- for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}" {% endfor -%}
    {%- endif -%}
{%- endblock widget_attributes -%}

{%- block hidden_row -%}
    {%- if freeze_display_text -%}
        <tr style="display: none">
            <td colspan="2">
                {{- form_widget(form) -}}
            </td>
        </tr>
    {%- else -%}
        {{- form_widget(form) -}}
    {%- endif -%}
{%- endblock hidden_row -%}

{%- block textarea_widget -%}
    {%- if freeze -%}
        {{- block('form_widget_simple') -}}
    {%- else -%}
        {{- parent() -}}
        {%- if help is defined and help is not empty -%}
            <p class="mini"><span class="attention">{{ help|trans({}, translation_domain) }}</span></p>
        {%- endif -%}
    {%- endif -%}
{%- endblock textarea_widget -%}

{%- block choice_widget_collapsed -%}
    {% if freeze %}
        {% set flag = false %}
        {% for choice in choices %}
            {% if choice is selectedchoice(value) %}
                {%- if freeze_display_text -%}
                    {{ choice.label|trans({}, translation_domain) }}
                {% endif %}
                <input type="hidden" value="{{ choice.value }}" {{ block('widget_attributes') }} />
                {% set flag = true %}
            {% endif %}
        {% endfor %}
        {% if flag == false %}<input type="hidden" value="" {{ block('widget_attributes') }} />{% endif %}
    {%- else -%}
        {{- parent() -}}
    {%- endif -%}
{%- endblock choice_widget_collapsed -%}


{%- block choice_widget_expanded -%}
    {% if freeze %}
        {%- if freeze_display_text -%}
            {{ form.vars.data.name|default(form.vars.data) }}
        {%- endif -%}
        <input type="hidden" value="{{ form.vars.data.id|default(form.vars.data) }}" {{ block('widget_attributes') }} />
    {%- else -%}
        {{- parent() -}}
    {%- endif -%}
{%- endblock choice_widget_expanded -%}


{%- block checkbox_widget -%}
    {%- if freeze -%}
        {%- if checked -%}
            {%- if freeze_display_text -%}
                {{ block('form_label') }}
            {%- endif -%}
            <input type="hidden" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %} />
        {%- endif -%}
    {%- else -%}
        {{- parent() -}}
    {%- endif -%}
{%- endblock checkbox_widget -%}

{%- block radio_widget -%}
    {%- if freeze -%}
        {%- if checked -%}
            {%- if freeze_display_text -%}
                {{ block('form_label') }}
            {%- endif -%}
            <input type="hidden" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %} />
        {%- endif -%}
    {%- else -%}
        {{- parent() -}}
    {%- endif -%}
{%- endblock radio_widget -%}


{%- block password_widget -%}
    {%- if freeze -%}
        <input type="hidden" {{ block('widget_attributes') }} value="{{ form.vars.data }}" />
    {%- else -%}
        {{- parent() -}}
    {%- endif -%}
{%- endblock password_widget -%}


{# EC-CUBE Widget #}

{%- block name_widget -%}
    {%- for child in form %}
        {{- form_errors(child) -}}
    {% endfor -%}
        {%- if freeze -%}
            {{- form_widget(form[form.vars.name01]) -}}
            {{- form_widget(form[form.vars.name02]) -}}
        {%- else -%}
            {{- form_widget(form[form.vars.name01]) -}}
            {{- form_widget(form[form.vars.name02]) -}}

        {%- endif -%}
        {%- if loop.last == false%}　{% endif -%}
{%- endblock name_widget -%}

{%- block tel_widget -%}
    {%- for child in form %}
        {{- form_errors(child) -}}
    {% endfor -%}
    {%- for child in form %}
        {{- form_widget(child, {'attr': {'style': 'ime-mode: disabled;'}}) -}}
        {%- if loop.last == false%}&nbsp;-&nbsp;{% endif -%}
    {% endfor -%}
{%- endblock tel_widget -%}

{%- block fax_widget -%}
    {%- for child in form %}
        {{- form_errors(child) -}}
    {% endfor -%}
    {%- for child in form %}
        {{- form_widget(child, {'attr': {'style': 'ime-mode: disabled;'}}) -}}
        {%- if loop.last == false%}&nbsp;-&nbsp;{% endif -%}
    {% endfor -%}
{%- endblock fax_widget -%}

{%- block zip_widget -%}
    {%- for child in form %}
        {{- form_errors(child) -}}
    {% endfor -%}
    {%- if freeze -%}
        〒&nbsp;{{ form_widget(form[form.vars.zip01_name]) }}&nbsp;-&nbsp;{{- form_widget(form[form.vars.zip02_name]) }}
    {%- else -%}
        〒&nbsp;{{ form_widget(form[form.vars.zip01_name], {'attr': {'style': 'ime-mode: disabled;'}}) }}&nbsp;-&nbsp;
        {{- form_widget(form[form.vars.zip02_name], {'attr': {'style': 'ime-mode: disabled;'}}) }}
        <a class="btn-normal" href="javascript:;" name="address_input" onclick="eccube.getAddress('{{ path('input_zip') }}', 'zip01', 'zip02', 'pref', 'addr01'); return false;">住所入力</a>
    {%- endif -%}
{%- endblock zip_widget -%}

{%- block address_widget -%}
    {%- for child in form %}
        {{- form_errors(child) -}}
    {% endfor -%}
    {%- if freeze -%}
        {{- form_widget(form[form.vars.pref_name]) -}}
        {{- form_widget(form[form.vars.addr01_name]) -}}
        {{- form_widget(form[form.vars.addr02_name]) -}}
    {%- else -%}
        {{- form_widget(form[form.vars.pref_name]) -}}<br />
        {{- form_widget(form[form.vars.addr01_name], {'attr': {'style': 'ime-mode: active;'}}) -}}<br />
        {{- form_widget(form[form.vars.addr02_name], {'attr': {'style': 'ime-mode: active;'}}) -}}<br />
        {%- if help is defined and help is not empty -%}
            <span class="attention">{{ help|trans({}, translation_domain) }}</span>
        {%- endif -%}
    {%- endif -%}
{%- endblock address_widget -%}
